// 创建路由模块routes，建立url到控制器controller的映射

// 创建路由并引入模块
const express = require('express');
// 文件上传中间件 multer的使用，将其添加到上传文件的路由中
const multer = require('multer');
const path = require('path');
const router = express.Router();
const upload = multer({
    dest: path.join(__dirname,"public/upload/temp")
})


const home = require('../controllers/home');
const image = require('../controllers/image');

module.exports = (app) => {
    router.get('/',home.index);
    router.get('/image/:image_id',image.index);
    // router.post('/image',image.create);
    // 在上传文件的路由上使用中间件
    router.post('/image',upload.single('file'),image.create)
    router.post('/image/:image_id/like',image.like);
    router.post('/image/:image_id/:comment',image.comment);
    // 使其绑定到app对象上去
    app.use(router);
}

